/*  This is mada by Kent    
 *  This source is made by Funms Team
 *  功能：组队任务：侏儒怪皇帝的复活
 *  @Author Kent 
 */

var minPlayers = 2;

function init() {
    em.setProperty("state", "0");
    em.setProperty("leader", "true");
}

function setup(level, leaderid) {
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    var eim = em.newInstance("Rex");
    eim.setProperty("checkdone", "0");
    eim.setInstanceMap(921120005).resetPQ(level);
    eim.setProperty("water", "0");
    eim.setInstanceMap(921120100).resetPQ(level);
    eim.setInstanceMap(921120200).resetPQ(level);
    eim.setInstanceMap(921120300).resetPQ(level);
    eim.setInstanceMap(921120400).resetPQ(level);

    var map = eim.getMapInstance(3);
    var mob = em.getMonster(9300281);//BOSS
    //eim.registerMonster(mob);
    //mob.changeLevel(level);
    //map.spawnMonsterOnGroundBelow(mob, map.getPortal(0).getPosition());
    eim.startEventTimer(1200000); //20 mins
    return eim;
}

function playerEntry(eim, player) {
    var map = eim.getMapInstance(0);
    player.changeMap(map, map.getPortal(0));
}

function playerRevive(eim, player) {
    return false;
}

function scheduledTimeout(eim) {
    end(eim);
}

function changedMap(eim, player, mapid) {
    if (mapid < 921120005 || mapid > 921120400) {
        eim.unregisterPlayer(player);

        if (eim.disposeIfPlayerBelow(0, 0)) {
            em.setProperty("state", "0");
            em.setProperty("leader", "true");
        }
    }
}

function playerDisconnected(eim, player) {
    return 0;
}

function monsterValue(eim, mobId) {
    return 1;
}

function playerExit(eim, player) {
    eim.unregisterPlayer(player);
    player.changeMap(em.getMapFactoryMap(211000002), em.getMapFactoryMap(211000002).getPortal(0));
    if (eim.disposeIfPlayerBelow(0, 0)) {
        em.setProperty("state", "0");
        em.setProperty("leader", "true");
    }
}

function end(eim) {
    eim.disposeIfPlayerBelow(100, 211000002);
    em.setProperty("state", "0");
    em.setProperty("leader", "true");
}

function clearPQ(eim) {
    end(eim);
}

function allMonstersDead(eim) {
}

function leftParty(eim, player) {
    end(eim);
}
function disbandParty(eim) {
    end(eim);
}
function playerDead(eim, player) {
}
function cancelSchedule() {
}

function pickUpItem(eim, player, itemID) {
}